package com.zeus.base.smscenter.restful.api.controller;


import com.mangofactory.swagger.annotations.ApiIgnore;
import com.wordnik.swagger.annotations.ApiOperation;
import com.zeus.base.smscenter.model.SmsLogInfo;
import com.zeus.base.smscenter.service.ISmsLogInfoService;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import com.zeus.base.smscenter.common.util.StringUtils;

/**
 * 发送短信
 *
 * @author linhaisong
 * @date 2015/12/21.
 */
@ApiIgnore
@RestController
@RequestMapping("/notifies")
public class NotifiesController {
    Logger log = Logger.getLogger(this.getClass());
    @Autowired
    private ISmsLogInfoService smsLogInfoService;

    @RequestMapping(value = "/queryReport", method = RequestMethod.POST)
    @ApiOperation(value = "助通短信状态报告",response =String.class)
    public String queryReport(@RequestParam(value = "param") String param) {
        log.info(param);
        String  returnMsg = "0";
        try {
            if(StringUtils.isEmpty(param)){
                returnMsg = "1";
            }else{
                String[] smsArr = param.split(";");
                for (int i=0;i<smsArr.length;i++){
                    String[] smsInfo = smsArr[i].split(",");
                    SmsLogInfo smsLogInfo = new SmsLogInfo();
                    smsLogInfo.setMessagePlatformId(smsInfo[0]);
                    smsLogInfo.setPhone(smsInfo[1]);
                    smsLogInfo.setOutResponseMessage(smsInfo[2].equals("1") ? "SUCCESS":"FAIL");
                    smsLogInfo.setIsSynchro("1");
                    smsLogInfoService.updateForZt(smsLogInfo);
                }
            }
        } catch (Exception exception) {
            log.error("参数:" + param + "系统错误:error:" + exception.getMessage());
            return  returnMsg;
        }
        return  returnMsg;
    }
}

